package com.xsomnus.java_basic.juc.exceptions;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author @叶小夏
 * @since 2019/7/29 0029 17:10
 * - 才需学也,学需静也/非淡泊无以明志，非宁静无以致远
 */
public class ThreadExceptionDemo {

    public static void main(String[] args) {
//        try {
//            Thread thread = new Thread(new ThreadExceptionRunner());
//            thread.start();
//        } catch (Exception e) {
//            System.out.println("-----main-thread error---------");
//            e.printStackTrace();
//        }
        // 这种情况下， 主线程是无法捕获子线程的异常， 而且在线程池中，子线程的出现异常，线程池通常回重新创建一个worker线程
        System.out.println("hello");
        try {
            ExecutorService es = Executors.newCachedThreadPool(new HandlerThreadFactory());
            es.execute(new ThreadExceptionRunner());
            es.shutdown();
        } catch (Exception e) {
            System.out.println("-----main-thread error---------");
            e.printStackTrace();
        }

    }
}
